<template>
  <div class="AddOrUpdate_main add_container showDetail column_three" :class="showKey.type">
    <div class="main_main">
      <el-form ref="form" :model="formData" :rules="rules" :inline="true">
        <div
          v-for="(item2,index2) in showKey.keys"
          :key="'index2'+index2"
          :class="getClass(item2)"
        >
          <el-form-item v-if="item2.type==='br'" class="showItem_br" />
          <el-form-item v-if="item2.type==='form'" :label="item2.name">
            <div v-if="!showData[item2.key]&&showData[item2.key]!==0&&showData[item2.key]!=='0'" class="show noData">暂无</div>
            <div v-else-if="item2.key==='status'" class="show">{{ showData[item2.key]==='1'||showData[item2.key]===1?'启用':'停用' }}</div>
            <div v-else class="show">{{ showData[item2.key] }}</div>
          </el-form-item>
          <el-form-item v-if="item2.type==='file'" :label="item2.name">
            <FileManageFull
              :file-names="showData[item2.fileName]"
              :file-real-names="showData[item2.fileRealName]"
              :file-urls="showData[item2.fileUrl]"
              :row-index="1"
              :readonly="true"
              @fileName="setFileName"
            />
          </el-form-item>

          <div v-if="item2.type==='table'&&item2.name" class="formItem_header">
            {{ item2.name }}
            <div class="button_item" @click="printM">
              <div class="button_item_padding">
                <svg-icon icon-class="打印" />
                打印
              </div>
            </div>
          </div>
          <div v-if="item2.type==='table'&& !item2.name" class="formItem_header" />
          <div v-if="item2.type==='table'" ref="table_container" class="table_container">
            <el-table
              ref="table"
              :data="showData[item2.key]"
              stripe
              border
              row-key="id"
              @selection-change="selectionChange"
            >
              <el-table-column type="selection" align="center" />

              <el-table-column
                v-for="(item3,index3) in item2.columns"
                :key="index3"
                :label="item3.name"
                :prop="item3.key"
                :min-width="item3.minWidth||100"
                :show-overflow-tooltip="true"
                :fixed="item3.fixed"
              >
                <template slot-scope="scope">
                  <div
                    v-if="item3.type==='column'"
                    style=" white-space:nowrap; text-overflow:ellipsis; overflow:hidden;"
                  >{{ scope.row[item3.key] }}</div>
                  <FileManage
                    v-if="item3.type==='file'"
                    :file-names.sync="scope.row[item3.fileName]"
                    :file-real-names.sync="scope.row[item3.fileRealName]"
                    :file-urls.sync="scope.row[item3.fileUrl]"
                    :row-index="scope.$index"
                    :readonly="true"
                    @fileName="setFileName"
                  />
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

      </el-form>
    </div>

  </div>
</template>

<script>
import { getReportUrl2 } from '@/api/superManage/reportForm'
import HeaderOperation_Print from '@/components/JLink/common/HeaderOperation_Print.vue'

export default {
  name: 'ShowDetailOld',
  props: {
    layerid: {},
    id: {},
    showKey: {},
    showData: {}
  },
  data() {
    return {
      mainId: 'id', // 表格行ID
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      formData: {
      },
      rules: {
      }
    }
  },
  mounted() {
    console.log(this.showKey)
  },
  methods: {// 表格拖动排序

    cancel() {
      this.$layer.close(this.layerid)// 关闭弹框
    },
    setFileName(...data) {
      this.tableData[data[3]].fileName = data[0]
      this.tableData[data[3]].fileRealName = data[1]
      this.tableData[data[3]].fileUrl = data[2]
    },
    getClass(item) {
      let res = ''
      if (item.type === 'form' || item.type === 'br') {
        res += 'showItem'
        if (item.length && item.length === 'double') {
          res += ' double'
        }
      } else if (item.type === 'file') {
        res += 'showItem double'
      } else {
        res += 'showTable'
      }

      return res
    },
    selectionChange(rows) {
      this.selectionsAll = rows
    },
    printM() {
      console.log(this.selectionsAll)
      let list = []
      if (this.selectionsAll && this.selectionsAll.length > 0) {
        list = this.selectionsAll
      } else {
        list = this.showData.details
      }
      if (list.length > 0) {
        getReportUrl2({
          ids: list.map(item => item.id).join(','),
          menuPath: '/warehouseManagement/elseEnterWarehouse2'
        }).then(res => {
          if (res.data.length == 1) {
            window.open(res.data[0].url)
          }
          if (res.data.length > 1) {
            this.$layer.iframe({// 弹框
              content: {
                content: HeaderOperation_Print, // 传递的组件对象
                parent: this, // 当前的vue对象
                data: {
                  rows: res.data
                }// props
              },
              area: ['400px', '150px'],
              title: '打印模板', // 标题
              shadeClose: false // 点击遮罩是否关闭
            })
          }
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .el-table__fixed-footer-wrapper {
  .el-table__cell:last-of-type {
    height: 39px !important;
  }
}

.main_main{

  .el-form{
    height: 100%;
    align-content: flex-start;

    .showItem{
      margin-left: 20px;
      margin-right: 20px;
      width: calc(33.33% - 40px);
    }

    /deep/ .el-form-item{
      width: 100%;
      border-bottom: 1px solid rgba(105,105,105,0.2);
      margin-left: 0;
      margin-right: 0;

      .el-form-item__label:before{
        content: none;
      }
      .el-form-item__label{
        color: #1F51B3;
        font-size: 15px;
      }
      .el-form-item__content{
        word-break: break-all;
        color: #333333;
        font-size: 15px;
        flex: 1;
        width: unset;
        margin-right: 0px;
      }
    }
    .double{
      width: calc(100% - 40px);
      //.show{
      //  overflow: hidden;
      //  text-overflow: ellipsis;
      //  display: -webkit-box;
      //  -webkit-line-clamp: 2;
      //  -webkit-box-orient: vertical;
      //}
    }
  }
  .showTable{
    width: 100%;
  }
}

.column_one{
  .showItem{
    width: 100% !important;
  }
}
.noData{
  color: #c0c4cc;
}
.show{
  height: fit-content !important;
  padding-top: 10px;
  padding-bottom: 10px;
}
.FileManageFull_container{
  padding-top: 10px;
  padding-left: 10px;
}
.showItem_br{
  border-bottom: 0 !important;
}
.formItem_header{
  font-size: 18px;
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding-left: 20px;
  padding-right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.table_container {
  padding-bottom: 20px !important;
  padding-top: 0px !important;
}
.el-table {
  font-size: 15px;
}

.button_item {
  font-size: 16px;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;

  .button_item_padding {
    padding: 0px 15px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    background-color: #387bfc;
  }

  .button_item_padding:hover {
    background-color: rgba(56, 123, 252,0.5);
    color: white;
  }

  .button_item_padding:active {
    background-color: rgba(56, 123, 252, 1);
  }

  .svg-icon {
    margin-right: 10px;
    width: 16px;
    height: 16px;
  }
}
</style>
